package com.guw.Swing;

import javax.swing.*;
import java.awt.*;

//图标,需要实现类,Frame继承
public class ICONDemo extends JFrame implements Icon{
    private int width;
    private int height;

    public ICONDemo(){
    }

    public ICONDemo(int width, int height) throws HeadlessException {
        this.width = width;
        this.height = height;
    }

    public static void main(String[] args) {
        new ICONDemo().init();
    }


    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }

    public void init(){
        ICONDemo iconDemo = new ICONDemo(15,15);
        JLabel label = new JLabel("图标测试:",iconDemo,SwingConstants.CENTER);

        Container container = getContentPane();
        container.add(label);

        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
}
